package com.AAL.DAO;

import java.sql.Date;
import java.util.List;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IProcessingOrderDAO;
import com.AAL.Model.Employee;
import com.AAL.Model.Order;
import com.AAL.Model.ProcessingOrder;
import com.AAL.Model.StatusOfOrder;
import com.AAL.Utils.HibernateUtil;

public class ProcessingOrderDAO implements IProcessingOrderDAO {

	@Override
	public ProcessingOrder saveAndUpdateProcessingOrder(
			ProcessingOrder processingOrder) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(processingOrder);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return processingOrder;
	}

	@Override
	public ProcessingOrder deleteProcessingOrder(int processingOrderID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			ProcessingOrder processingOrder = (ProcessingOrder) session.load(
					ProcessingOrder.class, processingOrderID);
			if (null != processingOrder) {
				session.delete(processingOrder);
			}
			session.getTransaction().commit();
			return processingOrder;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public ProcessingOrder getProcessingOrder(int processingOrderID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		ProcessingOrder processingOrder = (ProcessingOrder) session.load(
				ProcessingOrder.class, processingOrderID);
		return processingOrder;
	}

	@Override
	public List<Order> getOrderByEmployee(Employee employee,
			StatusOfOrder status, Date fromDate, Date toDate) {
		// TODO Auto-generated method stub
		return null;
	}

}
